package com.handsome.utils;

import com.handsome.entity.HsMenu;

import java.util.ArrayList;
import java.util.List;

public class MenuTreeUtil {

    public static List<HsMenu> generateTree(List<HsMenu> menus, Integer id) {
        List<HsMenu> newMenus = new ArrayList<>();
        for (HsMenu menu : menus) {
            if (menu.getParentId().equals(id)) {
                newMenus.add(menu);
            }
        }
        for (HsMenu nMenu : newMenus) {
            nMenu.setChildren(MenuTreeUtil.generateTree(menus, nMenu.getId()));
        }
        if (newMenus.size() == 0) {
            return null;
        }
        return newMenus;
    }


}
